package vn.com.epi.re.table;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

public class UserTable {
    
    public static final String NAME = "User";
    public static final  byte[] NAME_BYTES = Bytes.toBytes("User");
    public static final byte[] FAM_MAIN = Bytes.toBytes("main");
    public static final byte[] COL_VISITED_TIMESTAMPS = Bytes.toBytes("visitedTimestamps");
    public static final byte[] COL_VISITED_ARTICLES = Bytes.toBytes("visitedArticleIds");
    public static final byte[] COL_READING_PREFERENCES = Bytes.toBytes("readingPreferences");
    public static final byte[] COL_LAST_VISITED_TIMESTAMP = Bytes.toBytes("lastVisitedTimestamp");
    public static final byte[] COL_TOTAL_VISITED_COUNT = Bytes.toBytes("totalVisitedCount");
        
    public UserTable() {     
        
    }
    
    public static String getVisitedTimestamps(Result result) {
        try {
            String timestamps = Bytes.toString(result.getValue(FAM_MAIN, COL_VISITED_TIMESTAMPS));
            if (timestamps == null)
                timestamps = "";
            return timestamps;
        } catch (Exception e) {
            return "";
        }
    }
    
    public static String getVisitedArticles(Result result) {
        try {
            String articles = Bytes.toString(result.getValue(FAM_MAIN, COL_VISITED_ARTICLES));
            if (articles == null)
                articles = "";
            return articles;
        } catch (Exception e) {
            return "";
        }        
    }
    
    public static String getReadingPreferences(Result result) {
        try {
            String preferences = Bytes.toString(result.getValue(FAM_MAIN, COL_READING_PREFERENCES));
            if (preferences == null)
                preferences = "";
            return preferences;
        } catch (Exception e) {
            return "";
        }                
    }

//    public static String getRecommendation(Result result) {
//        String re;
//        try {
//            re = Bytes.toString(result.getValue(FAM_MAIN, COL_RECOMMENDATIONS));
//        } catch (Exception e) {
//            re = "";
//        }
//        return re;
//    }

}
